package org.reos.ReGenerator;

import org.stringtemplate.v4.*;

import java.util.Date;

public class ReGenerator {

    private STGroup src_group;
    private ST      src_templ;
    private STGroup inc_group;
    private ST      inc_templ;


    public ReGenerator() {
	// write your code here

        src_group = new STGroupFile("..\\ReTest\\source.stg");
        src_templ = src_group.getInstanceOf("reos_source_template");

        inc_group = new STGroupFile("..\\ReTest\\header.stg");
        inc_templ = inc_group.getInstanceOf("reos_header_template");

    }

    public void FillData() {

        TASK t1 = new TASK();
        t1.CLASS = "EXTENDED";
        t1.NAME = "tsk1";
        t1.PRIO = 1;
        t1.STACK = 32;

        TASK t2 = new TASK();
        t2.CLASS = "EXTENDED";
        t2.NAME = "tsk2";
        t2.PRIO = 1;
        t2.STACK = 128;

        EVENT e1 = new EVENT();
        e1.NAME = "evt1";

        EVENT e2 = new EVENT();
        e2.NAME = "evt2";

        ISR i1 = new ISR();
        i1.HANDLER = "UART_Isr";
        i1.TYPE = "NORMAL";
        i1.VECTOR = "UART1_vector";

        ISR i2 = new ISR();
        i2.HANDLER = "TMR_Isr";
        i2.TYPE = "FAST";
        i2.VECTOR = "TMR_A1_vector";

        Message m1 = new Message();
        m1.NAME = "msg1";

        SYSTEM s = new SYSTEM();
        s.SOURCE_OUT = "reos_config.c";
        s.HEADER_OUT = "reos_config.h";

        src_templ.add("TASK",t1);
        src_templ.add("TASK",t2);

        src_templ.add("EVENT",e1);
        src_templ.add("EVENT",e2);

        src_templ.add("ISR",i1);
        src_templ.add("ISR",i2);

        src_templ.add("SYSTEM",s);

        inc_templ.add("ISR",i1);
        inc_templ.add("ISR",i2);

        inc_templ.add("TASK",t1);
        inc_templ.add("TASK",t2);

        inc_templ.add("EVENT",e1);
        inc_templ.add("EVENT",e2);

        inc_templ.add("MESSAGE",m1);

        inc_templ.add("SYSTEM",s);
    }

    public void Generate() {
        System.out.println(src_templ.render());
        System.out.println(inc_templ.render());
        //st.inspect();
    }
}

class TASK {
    public String NAME;
    public String CLASS;
    public int PRIO;
    public int STACK;
}

class EVENT {
    public String NAME;
}

class Message {
    public String NAME;
}

class ISR {
    public String HANDLER;
    public String TYPE;
    public String VECTOR;
}

class SYSTEM {
    public String DATE;
    public String SOURCE_OUT;
    public String HEADER_OUT;
    SYSTEM() {
        DATE = new Date().toString();
    }
}